	$(function(){
		var params = {};        
		$("#but_register").click(function(){                
			var email = document.getElementById("inp_email").value;
            var p1 = document.getElementById("inp_p1").value,p2=document.getElementById("inp_p2").value;
			var add_pro = document.getElementById("addr_pro").value;
			var protocol = document.getElementById("chk_protocol").checked;
            var account_type = document.getElementById("account_type").value;
            
            params.account_type = account_type;
			params.gender = $("input[name='gender']:checked").val();
			
			if(email.length == 0) {
				pop.alert(-1, "电子邮件不能为空");
				return false;
			} else {
				params.email = email;
			}
			
			if(p1.length < 6 || p1.length > 32) {
				pop.alert(-1, "密码必须是6-32位的英文字母或数字");
				return false;
			}

			if( p1 !== p2) {
				pop.alert(-1, "两次输入的密码不一致");
				return false;				
			}

            if(protocol === false) {
                pop.alert(-1, "请仔细阅读注册协议");
                return false;
            }

			params.password = p1;
            
            /**扩展**/
            var user_name = document.getElementById("inp_name");
                if(user_name) {
                    if(user_name.length == 0) {
                        pop.alert(-1, "用户名不能为空");
                        return false;
                    } else {
                        params.user_name = user_name.value;
                    }
                }

            var contact = document.getElementById("inp_contact");
                if(contact) {
                    if(contact.length == 0) {
                        pop.alert(-1, "联系人不能为空");
                        return false;
                    } else {
                        params.contact = contact.value;
                    }
                }

            var company_name = document.getElementById("inp_c_name");
                if(company_name) {
                    if(company_name.value) {
                        params.company_name = company_name.value;
                    } else {
                        pop.alert(-1, "请填写企业名称");
                        return false;
                    }
                }

            var user_post = document.getElementById("inp_post");   
                if(user_post) {
                    if(user_post.value) {
                        params.contact_post = user_post.value;
                    } else {
                        pop.alert(-1, "请填写您的职位");
                        return false;                        
                    }
                }
            
            var telephone = document.getElementById("inp_telephone");
                if(telephone) {
                    if(telephone.value){
                        params.telephone = telephone.value;
                    } else {
                        pop.alert(-1, "请填写公司固定电话");
                        return false;
                    }
                }

            var service_tel = document.getElementById("inp_service_tel");
            if(telephone) {
                if(telephone.value){
                    params.service_tel = service_tel.value;
                }
                else
                {
                    params.service_tel = 0;
                }
            }

            var fax = document.getElementById("inp_fax");
                if(fax) {
                    if(fax.value) {
                        params.fax = fax.value;
                    } else {
                        pop.alert(-1, "请填写公司传真");
                        return false;
                    }
                }
                
            var mobile = document.getElementById("inp_mobile");
                if(mobile) {
                    if(mobile.value) {
                        params.mobile = mobile.value;
                    } else {
                        pop.alert(-1, "请填写移动电话");
                        return false;                        
                    }
                }
            
            var web_site = document.getElementById("inp_web_site");
                if(web_site) {
                    if(web_site.value) {
                        params.web_site = web_site.value;
                    } else {
                        pop.alert(-1, "请填写公司网址");
                        return false;                        
                    }
                }
                
            var company_capital = document.getElementById("inp_capital");  
                if(company_capital) {
                    if(company_capital.value) {
                        params.company_capital = company_capital.value;
                    } else {
                        pop.alert(-1, "请填写注册资本,仅客服可见");
                        return false;                        
                    }
                }            
            
			if(add_pro == 0) {
				pop.alert(-1, "请选择你所在的省份");
				return false;
			} else {
				params.addr_pro = add_pro;
				params.addr_city = document.getElementById("addr_city").value;
				params.addr_area = document.getElementById("addr_area").value;
                var addr_detail  = document.getElementById("inp_addr_detail");
                    params.addr_detail = addr_detail ? addr_detail.value : '';
			}

            var commission_area = document.getElementById("commission_list");
                if(commission_area) {
                    var commission = [];
                    $("#commission_list input:checked").each(function(){
                        commission.push( $(this).val() );
                    });
                    params.commission = commission.join(",");
                }

			$.post(SITE_URL+'/user/register/save',params,function(r){
                if(r.status > 0) {
                	pop.alert(1, "注册成功,请登录!");
                } else {                    
                    if(r.status == '-11') {
                        pop.alert(-1, "该用户已注册,请登录");
                        pop.open('user/login');
                    } else {
                        pop.alert(-1, r.message);				
                    }
                }
			});
		});
	})